import paramiko

class SSHClientWrapper:
    def __init__(self, host, port=22, username=None, password=None, pkey=None, proxy=None):
        self.host = host
        self.port = port
        self.username = username
        self.password = password
        self.pkey = pkey
        self.proxy = proxy
        self.client = None

    def connect(self):
        self.client = paramiko.SSHClient()
        self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        connect_params = {
            'hostname': self.host,
            'port': self.port,
            'username': self.username,
            'password': self.password,
            'pkey': self.pkey
        }
        if self.proxy:
            connect_params['sock'] = self.proxy
        self.client.connect(**{k: v for k, v in connect_params.items() if v is not None})

    def exec_command(self, command):
        if not self.client:
            raise Exception('SSH client not connected')
        stdin, stdout, stderr = self.client.exec_command(command)
        return stdout.read().decode(), stderr.read().decode()

    def close(self):
        if self.client:
            self.client.close()
            self.client = None